import os
from google.appengine.api import users
from google.appengine.ext.webapp import template
from imphandler import ImpHandler

class AwesomePage(ImpHandler):
	def notAuthenticated(self):
		if self.IsSecure():
			self.redirect_login()

	def processRequest(self):
		if self.OnGet():
			path = os.path.join(os.path.dirname(__file__), "awsm.tpl")
			userName = ''
			if self.user:
				userName = self.user.nickname()
			
				
			isLoggedIn = False;
			if userName != '':
				isLoggedIn = False

			dataset = {
				'userName': userName, 
				'isLoggedIn': isLoggedIn, 
				'signInUrl':users.create_login_url(self.request.uri),
				'head': self.render_head(),
				'content': self.render_content()
			}

			html = template.render(path, dataset)
			self.response.out.write(html)

	def redirect_login(self):
		self.redirect(users.create_login_url(self.request.uri))
	
	def render_head(self):
		path = os.path.join(os.path.dirname(__file__), self.head_template())
		return template.render(path, self.head_dataset())
	def render_content(self):
		path = os.path.join(os.path.dirname(__file__), self.content_template())
		return template.render(path, self.content_dataset())

